import java.util.Scanner;

public class Day_19_2_查找最长公共子串 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str1 = sc.nextLine();
        String str2 = sc.nextLine();

        if(str1.length() <= str2.length()) {
            compare(str1,str2);
        } else {
            compare(str2, str1);
        }
    }

    public static void compare(String str1, String str2) {
        String str = "";
        for(int i = 0; i < str1.length(); i++) {
            StringBuilder sb = new StringBuilder();
            for(int j = i; j < str1.length();j++) {
                if(str2.contains(sb.append(str1.charAt(j)))) {
                    if(sb.length() > str.length()) {
                        str = sb.toString();
                    }
                }
            }
        }
        System.out.println(str);
    }
}
